<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="客户ID" prop="customerId">
      <el-input v-model="dataForm.customerId" placeholder="客户ID"></el-input>
    </el-form-item>
    <el-form-item label="订单号" prop="orderNo">
      <el-input v-model="dataForm.orderNo" placeholder="订单号"></el-input>
    </el-form-item>
    <el-form-item label="起始地点" prop="startLocation">
      <el-input v-model="dataForm.startLocation" placeholder="起始地点"></el-input>
    </el-form-item>
    <el-form-item label="起始地点经度" prop="startPointLongitude">
      <el-input v-model="dataForm.startPointLongitude" placeholder="起始地点经度"></el-input>
    </el-form-item>
    <el-form-item label="起始点伟度" prop="startPointLatitude">
      <el-input v-model="dataForm.startPointLatitude" placeholder="起始点伟度"></el-input>
    </el-form-item>
    <el-form-item label="结束地点" prop="endLocation">
      <el-input v-model="dataForm.endLocation" placeholder="结束地点"></el-input>
    </el-form-item>
    <el-form-item label="结束地点经度" prop="endPointLongitude">
      <el-input v-model="dataForm.endPointLongitude" placeholder="结束地点经度"></el-input>
    </el-form-item>
    <el-form-item label="结束地点经度" prop="endPointLatitude">
      <el-input v-model="dataForm.endPointLatitude" placeholder="结束地点经度"></el-input>
    </el-form-item>
    <el-form-item label="预估里程" prop="expectDistance">
      <el-input v-model="dataForm.expectDistance" placeholder="预估里程"></el-input>
    </el-form-item>
    <el-form-item label="实际里程" prop="realDistance">
      <el-input v-model="dataForm.realDistance" placeholder="实际里程"></el-input>
    </el-form-item>
    <el-form-item label="预估订单金额" prop="expectAmount">
      <el-input v-model="dataForm.expectAmount" placeholder="预估订单金额"></el-input>
    </el-form-item>
    <el-form-item label="实际订单金额" prop="realAmount">
      <el-input v-model="dataForm.realAmount" placeholder="实际订单金额"></el-input>
    </el-form-item>
    <el-form-item label="顾客好处费" prop="favourFee">
      <el-input v-model="dataForm.favourFee" placeholder="顾客好处费"></el-input>
    </el-form-item>
    <el-form-item label="司机ID" prop="driverId">
      <el-input v-model="dataForm.driverId" placeholder="司机ID"></el-input>
    </el-form-item>
    <el-form-item label="司机接单时间" prop="acceptTime">
      <el-input v-model="dataForm.acceptTime" placeholder="司机接单时间"></el-input>
    </el-form-item>
    <el-form-item label="司机到达时间" prop="arriveTime">
      <el-input v-model="dataForm.arriveTime" placeholder="司机到达时间"></el-input>
    </el-form-item>
    <el-form-item label="开始服务时间" prop="startServiceTime">
      <el-input v-model="dataForm.startServiceTime" placeholder="开始服务时间"></el-input>
    </el-form-item>
    <el-form-item label="结束服务时间" prop="endServiceTime">
      <el-input v-model="dataForm.endServiceTime" placeholder="结束服务时间"></el-input>
    </el-form-item>
    <el-form-item label="微信付款时间" prop="payTime">
      <el-input v-model="dataForm.payTime" placeholder="微信付款时间"></el-input>
    </el-form-item>
    <el-form-item label="订单取消规则ID" prop="cancelRuleId">
      <el-input v-model="dataForm.cancelRuleId" placeholder="订单取消规则ID"></el-input>
    </el-form-item>
    <el-form-item label="车牌号" prop="carLicense">
      <el-input v-model="dataForm.carLicense" placeholder="车牌号"></el-input>
    </el-form-item>
    <el-form-item label="车型" prop="carType">
      <el-input v-model="dataForm.carType" placeholder="车型"></el-input>
    </el-form-item>
    <el-form-item label="司机到达拍照：车前照" prop="carFrontUrl">
      <el-input v-model="dataForm.carFrontUrl" placeholder="司机到达拍照：车前照"></el-input>
    </el-form-item>
    <el-form-item label="司机到达拍照：车后照" prop="carBackUrl">
      <el-input v-model="dataForm.carBackUrl" placeholder="司机到达拍照：车后照"></el-input>
    </el-form-item>
    <el-form-item label="微信支付订单号" prop="transactionId">
      <el-input v-model="dataForm.transactionId" placeholder="微信支付订单号"></el-input>
    </el-form-item>
    <el-form-item label="工作編號" prop="jobId">
      <el-input v-model="dataForm.jobId" placeholder="工作編號"></el-input>
    </el-form-item>
    <el-form-item label="订单状态：1等待接单，2已接单，3司机已到达，4开始代驾，5结束代驾，6未付款，7已付款，8订单已结束，9顾客撤单，10司机撤单，11事故关闭，12其他" prop="status">
      <el-input v-model="dataForm.status" placeholder="订单状态：1等待接单，2已接单，3司机已到达，4开始代驾，5结束代驾，6未付款，7已付款，8订单已结束，9顾客撤单，10司机撤单，11事故关闭，12其他"></el-input>
    </el-form-item>
    <el-form-item label="订单备注信息" prop="remark">
      <el-input v-model="dataForm.remark" placeholder="订单备注信息"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="修改时间" prop="updateTime">
       
<el-input v-model="dataForm.updateTime" placeholder="修改时间"></el-input>
    </el-form-item>
    <el-form-item label="是否删除" prop="isDeleted">    
        <el-input v-model="dataForm.isDeleted" placeholder="是否删除"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          customerId: '',
          orderNo: '',
          startLocation: '',
          startPointLongitude: '',
          startPointLatitude: '',
          endLocation: '',
          endPointLongitude: '',
          endPointLatitude: '',
          expectDistance: '',
          realDistance: '',
          expectAmount: '',
          realAmount: '',
          favourFee: '',
          driverId: '',
          acceptTime: '',
          arriveTime: '',
          startServiceTime: '',
          endServiceTime: '',
          payTime: '',
          cancelRuleId: '',
          carLicense: '',
          carType: '',
          carFrontUrl: '',
          carBackUrl: '',
          transactionId: '',
          jobId: '',
          status: '',
          remark: '',
          createTime: '',
          updateTime: '',
          isDeleted: ''
        },
        dataRule: {
          customerId: [
            { required: true, message: '客户ID不能为空', trigger: 'blur' }
          ],
          orderNo: [
            { required: true, message: '订单号不能为空', trigger: 'blur' }
          ],
          startLocation: [
            { required: true, message: '起始地点不能为空', trigger: 'blur' }
          ],
          startPointLongitude: [
            { required: true, message: '起始地点经度不能为空', trigger: 'blur' }
          ],
          startPointLatitude: [
            { required: true, message: '起始点伟度不能为空', trigger: 'blur' }
          ],
          endLocation: [
            { required: true, message: '结束地点不能为空', trigger: 'blur' }
          ],
          endPointLongitude: [
            { required: true, message: '结束地点经度不能为空', trigger: 'blur' }
          ],
          endPointLatitude: [
            { required: true, message: '结束地点经度不能为空', trigger: 'blur' }
          ],
          expectDistance: [
            { required: true, message: '预估里程不能为空', trigger: 'blur' }
          ],
          realDistance: [
            { required: true, message: '实际里程不能为空', trigger: 'blur' }
          ],
          expectAmount: [
            { required: true, message: '预估订单金额不能为空', trigger: 'blur' }
          ],
          realAmount: [
            { required: true, message: '实际订单金额不能为空', trigger: 'blur' }
          ],
          favourFee: [
            { required: true, message: '顾客好处费不能为空', trigger: 'blur' }
          ],
          driverId: [
            { required: true, message: '司机ID不能为空', trigger: 'blur' }
          ],
          acceptTime: [
            { required: true, message: '司机接单时间不能为空', trigger: 'blur' }
          ],
          arriveTime: [
            { required: true, message: '司机到达时间不能为空', trigger: 'blur' }
          ],
          startServiceTime: [
            { required: true, message: '开始服务时间不能为空', trigger: 'blur' }
          ],
          endServiceTime: [
            { required: true, message: '结束服务时间不能为空', trigger: 'blur' }
          ],
          payTime: [
            { required: true, message: '微信付款时间不能为空', trigger: 'blur' }
          ],
          cancelRuleId: [
            { required: true, message: '订单取消规则ID不能为空', trigger: 'blur' }
          ],
          carLicense: [
            { required: true, message: '车牌号不能为空', trigger: 'blur' }
          ],
          carType: [
            { required: true, message: '车型不能为空', trigger: 'blur' }
          ],
          carFrontUrl: [
            { required: true, message: '司机到达拍照：车前照不能为空', trigger: 'blur' }
          ],
          carBackUrl: [
            { required: true, message: '司机到达拍照：车后照不能为空', trigger: 'blur' }
          ],
          transactionId: [
            { required: true, message: '微信支付订单号不能为空', trigger: 'blur' }
          ],
          jobId: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '订单状态：1等待接单，2已接单，3司机已到达，4开始代驾，5结束代驾，6未付款，7已付款，8订单已结束，9顾客撤单，10司机撤单，11事故关闭，12其他不能为空', trigger: 'blur' }
          ],
          remark: [
            { required: true, message: '订单备注信息不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          isDeleted: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/order/orderinfo/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 200) {
                this.dataForm.customerId = data.orderInfo.customerId
                this.dataForm.orderNo = data.orderInfo.orderNo
                this.dataForm.startLocation = data.orderInfo.startLocation
                this.dataForm.startPointLongitude = data.orderInfo.startPointLongitude
                this.dataForm.startPointLatitude = data.orderInfo.startPointLatitude
                this.dataForm.endLocation = data.orderInfo.endLocation
                this.dataForm.endPointLongitude = data.orderInfo.endPointLongitude
                this.dataForm.endPointLatitude = data.orderInfo.endPointLatitude
                this.dataForm.expectDistance = data.orderInfo.expectDistance
                this.dataForm.realDistance = data.orderInfo.realDistance
                this.dataForm.expectAmount = data.orderInfo.expectAmount
                this.dataForm.realAmount = data.orderInfo.realAmount
                this.dataForm.favourFee = data.orderInfo.favourFee
                this.dataForm.driverId = data.orderInfo.driverId
                this.dataForm.acceptTime = data.orderInfo.acceptTime
                this.dataForm.arriveTime = data.orderInfo.arriveTime
                this.dataForm.startServiceTime = data.orderInfo.startServiceTime
                this.dataForm.endServiceTime = data.orderInfo.endServiceTime
                this.dataForm.payTime = data.orderInfo.payTime
                this.dataForm.cancelRuleId = data.orderInfo.cancelRuleId
                this.dataForm.carLicense = data.orderInfo.carLicense
                this.dataForm.carType = data.orderInfo.carType
                this.dataForm.carFrontUrl = data.orderInfo.carFrontUrl
                this.dataForm.carBackUrl = data.orderInfo.carBackUrl
                this.dataForm.transactionId = data.orderInfo.transactionId
                this.dataForm.jobId = data.orderInfo.jobId
                this.dataForm.status = data.orderInfo.status
                this.dataForm.remark = data.orderInfo.remark
                this.dataForm.createTime = data.orderInfo.createTime
                this.dataForm.updateTime = data.orderInfo.updateTime
                this.dataForm.isDeleted = data.orderInfo.isDeleted
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/order/orderinfo/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'customerId': this.dataForm.customerId,
                'orderNo': this.dataForm.orderNo,
                'startLocation': this.dataForm.startLocation,
                'startPointLongitude': this.dataForm.startPointLongitude,
                'startPointLatitude': this.dataForm.startPointLatitude,
                'endLocation': this.dataForm.endLocation,
                'endPointLongitude': this.dataForm.endPointLongitude,
                'endPointLatitude': this.dataForm.endPointLatitude,
                'expectDistance': this.dataForm.expectDistance,
                'realDistance': this.dataForm.realDistance,
                'expectAmount': this.dataForm.expectAmount,
                'realAmount': this.dataForm.realAmount,
                'favourFee': this.dataForm.favourFee,
                'driverId': this.dataForm.driverId,
                'acceptTime': this.dataForm.acceptTime,
                'arriveTime': this.dataForm.arriveTime,
                'startServiceTime': this.dataForm.startServiceTime,
                'endServiceTime': this.dataForm.endServiceTime,
                'payTime': this.dataForm.payTime,
                'cancelRuleId': this.dataForm.cancelRuleId,
                'carLicense': this.dataForm.carLicense,
                'carType': this.dataForm.carType,
                'carFrontUrl': this.dataForm.carFrontUrl,
                'carBackUrl': this.dataForm.carBackUrl,
                'transactionId': this.dataForm.transactionId,
                'jobId': this.dataForm.jobId,
                'status': this.dataForm.status,
                'remark': this.dataForm.remark,
                'createTime': this.dataForm.createTime,
                'updateTime': this.dataForm.updateTime,
                'isDeleted': this.dataForm.isDeleted
              })
            }).then(({data}) => {
              if (data && data.code === 200) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
